package com.aboo.dao.personnel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.aboo.constant.CommonConstant;
import com.aboo.dao.BaseDao;
import com.aboo.parameter.personnel.LoginParameter;
import com.aboo.po.BasePO;
import com.aboo.po.personnel.LoginPO;
import com.aboo.util.ArrayListUtils;

public class LoginDao extends BaseDao implements ILoginDao {

	public List<LoginPO> findByCondition(LoginParameter param) {
		List<LoginPO> result = null;
		
		if (param != null) {
			StringBuffer hql = new StringBuffer(" from LoginPO where inuse='" + CommonConstant.INUSE_YES + "'");
			Map<String, Object> params = new HashMap<String, Object>();
			if (param.getName() != null) {
				hql.append(" and name=:name");
				params.put("name", param.getName());
			}
			if (param.getPassword() != null) {
				hql.append(" and password=:password");
				params.put("password", param.getPassword());
			}
			if (param.getRealName() != null) {
				hql.append(" and realName=:realName");
				params.put("realName", param.getRealName());
			}
			if (param.getNickName() != null) {
				hql.append(" and nickName=:nickName");
				params.put("nickName", param.getNickName());
			}
			if (param.getSex() != null) {
				hql.append(" and sex=:sex");
				params.put("sex", param.getSex());
			}
			
			result = new ArrayListUtils<LoginPO, BasePO>().convert((this.findByCondition(hql.toString(), params)));
		}
		
		return result;
	}
	
}
